package com.member.provider.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.member.dto.ChannelMember;
import com.member.provider.service.ChannelMemberService;
import com.member.utils.Result;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 银狐先生
 * @auther liujian
 * @date 2023/12/12 17:00
 */
@RestController
@RequestMapping("/provider/channel")
@CrossOrigin
public class MemberChannelManage {

    @Autowired
    private ChannelMemberService memberchannelservice;




    /**
     * @Description TODO
     * @param
     * @retuen List<ChannelMember>
     * @date 2023/12/13 13:56
     * @auther 银狐先生
     * 渠道管理
     *
     */
    @PostMapping ("/getlist/{page}/{size}")
    public Result getChannelList( @RequestBody ChannelMember channelMember,
                                  @PathVariable Integer page,
                                  @PathVariable Integer size,
                                  @RequestHeader("token") String token
                                ){
        //解析token
        Claims claims = Jwts.parser()
                .setSigningKey("xft-ymt")
                .parseClaimsJws(token)
                .getBody();
        //渠道ID为主索引，主要管理渠道相关交易参数
        LambdaQueryWrapper<ChannelMember> queryWrapper = new LambdaQueryWrapper<>();
        if (channelMember.getChannelId()!=null) {
            queryWrapper.eq(ChannelMember::getChannelId, channelMember.getChannelId());
        }
        return Result.success(memberchannelservice.page(new Page<>(page, size), queryWrapper));
    }

    /**
     * @Description TODO
     * @param channelId
     * @retuen Integer
     * @date 2023/12/13 16:06
     * @auther 银狐先生
     */
    public Integer deleteByPrimaryKey(String channelId){
        Integer deleteCode=memberchannelservice.deleteByPrimaryKey(channelId);
        return deleteCode;
    }




    /**
     * @Description TODO
     * @param record
     * @retuen int
     * @date 2023/12/14 16:59
     * @auther 银狐先生 
     */
    @GetMapping ("/insertMemberChannel")
    public Result toH5Mange(ChannelMember record){
        int insert = memberchannelservice.insert(record);
        if (insert > 0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }


    /**
     * @Description TODO
     * @param channelId
     * @retuen Result
     * @date 2023/12/15 13:48
     * @auther 银狐先生
     */
    @GetMapping("/deleteChannelByid")
    public Result deleteChannelByid(String channelId){
        int i = memberchannelservice.deleteByPrimaryKey(channelId);
        if (i>0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    /**
     * @Description TODO
     * @param record
     * @retuen Result
     * @date 2023/12/15 13:55
     * @auther 银狐先生
     *判断字段是否为空添加
     */
    @PostMapping("/insertSelective")
    public Result insertSelective(ChannelMember record){
        int i = memberchannelservice.insertSelective(record);
        if (i>0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }

    /**
     * @Description TODO
     * @param channelId
     * @retuen result
     * @date 2023/12/15 14:12
     * @auther 银狐先生
     * 根据id查询渠道
     */
    @GetMapping("/selectByPrimaryKey")
    public Result selectByPrimaryKey(String channelId){
        ChannelMember  record = memberchannelservice.selectByPrimaryKey(channelId);
        return Result.success(record);
    }

    /**
     * @Description TODO
     * @param record
     * @retuen Result
     * @date 2023/12/15 14:16
     * @auther 银狐先生
     * 根据字段非空修改
     */
    @PostMapping("updateByPrimaryKeySelective")
    public Result updateByPrimaryKeySelective(ChannelMember record){
        int i = memberchannelservice.updateByPrimaryKeySelective(record);
        if (i>0){
            return Result.success("修改成功");
        }
        return Result.error("修改失败");
    }

    /**
     * @Description TODO
     * @param record
     * @retuen Result
     * @date 2023/12/15 14:19
     * @auther 银狐先生
     * 批量修改
     */
    @PostMapping("updatSelectiveByPrimaryKey")
    public Result updatSelectiveByPrimaryKey(ChannelMember record){
        int i = memberchannelservice.updateByPrimaryKey(record);
        if (i>0){
            return Result.success("修改成功");
        }
        return Result.error("修改失败");
    }









}
